// import { adapter } from "@/utils";
import { request } from "../request";
// import { adapterOfFetchUserList } from "./management.adapter";

/** 获取用户列表 */
export const fetchUserList = async (
	input: UserManagement.GetUserInfoListInput,
) => {
	const data = await request.post<PageOutput<ApiUserManagement.User[] | null>>(
		"/useraccount/userinfos",
		input,
	);
	return data;
	// return adapter(adapterOfFetchUserList, data);
};

export const fetchRoleList = async () => {
	const data = await request.get<SystemManagement.Role[] | null>("/menu/roles");
	return data;
};

export const fetchMenuTreeList = async () => {
	const data = await request.get<SystemManagement.MenuTree[] | null>(
		"/menu/menu-trees",
	);
	return data;
};

export async function fetchRoleMenus(roleId: number) {
	const data = await request.get<SystemManagement.RoleMenus | null>(
		"/menu/role-menus/" + roleId,
	);
	return data;
}

export async function saveRoleMenus(
	input: SystemManagement.SaveRoleMenusInput,
) {
	const data = await request.post("/menu/role-menus", input);
	return data;
}

/**
 * 删除角色
 * @param input
 * @returns
 */
export async function delRole(roleId: number) {
	const data = await request.delete("/menu/role/" + roleId);
	return data;
}

/**
 * 新增或修改角色
 * @param input
 * @returns
 */
export async function addOrUpdateRole(
	input: SystemManagement.AddOrUpdateRoleInput,
) {
	const data = await request.post<SystemManagement.Role>(
		"/menu/addOrUpdateRole",
		input,
	);
	return data;
}
